using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;

namespace WindowsGame1
{
    public class Timer
    {
        long lastElapsed = -1;
        long elapsed = 0;
        public long ElapsedSinceStart
        {
            get { return elapsed; }
            set { elapsed = value; }
        }

        float delta = 0;
        public float Delta
        {
            get { return delta; }
        }

        double total = 0;
        public double Total
        {
            get { return total; }
        }

        bool paused = false;
        public bool Paused
        {
            get { return paused; }
            set { paused = value; }
        }

        Stopwatch watch = new Stopwatch();
        public System.Diagnostics.Stopwatch Watch
        {
            get { return watch; }
            set { watch = value; }
        }

        public void Update()
        {
            if (lastElapsed == -1)
            {
                watch.Reset();
                watch.Start();
                lastElapsed = 0;
                elapsed = 0;
            }
            else
            {
                lastElapsed = elapsed;
                elapsed = watch.ElapsedMilliseconds;

                if (!paused)
                {
                    delta = (float)(elapsed - lastElapsed) / 1000.0f;
                    total += (double)delta;
                }
            }
        }
    }
}
